<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Detailed Semantics -- Free Functions</title>
<link rel="stylesheet" href="../../../../../../../doc/src/boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.78.1">
<link rel="home" href="../../../index.html" title="Boost.Optional">
<link rel="up" href="../../../optional/reference/header__boost_optional_optional_hpp_.html" title="Header &lt;boost/optional/optional.hpp&gt;">
<link rel="prev" href="detailed_semantics____optional_references.html" title="Detailed Semantics -- Optional References">
<link rel="next" href="header__boost_optional_hpp_.html" title="Header &lt;boost/optional.hpp&gt;">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../../boost.png"></td>
<td align="center"><a href="../../../../../../../index.html">Home</a></td>
<td align="center"><a href="../../../../../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
<td align="center"><a href="../../../../../../../more/index.htm">More</a></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="detailed_semantics____optional_references.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../../../optional/reference/header__boost_optional_optional_hpp_.html"><img src="../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="header__boost_optional_hpp_.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="boost_optional.reference.header__boost_optional_optional_hpp_.detailed_semantics____free_functions"></a><a class="link" href="detailed_semantics____free_functions.html" title="Detailed Semantics -- Free Functions">Detailed
        Semantics -- Free Functions</a>
</h4></div></div></div>
<p>
          <span class="inlinemediaobject"><img src="../../../images/space.png" alt="space"></span>
        </p>
<a name="reference_make_optional_value"></a><div class="blockquote"><blockquote class="blockquote"><p>
            <code class="computeroutput"><span class="identifier">optional</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;</span> <span class="identifier">make_optional</span><span class="special">(</span>
            <span class="identifier">T</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">v</span> <span class="special">)</span></code>
          </p></blockquote></div>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
              <span class="bold"><strong>Returns: </strong></span> <code class="computeroutput"><span class="identifier">optional</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;(</span><span class="identifier">v</span><span class="special">)</span></code> for the <span class="emphasis"><em>deduced</em></span>
              type <code class="computeroutput"><span class="identifier">T</span></code> of <code class="computeroutput"><span class="identifier">v</span></code>.
            </li>
<li class="listitem">
              <span class="bold"><strong>Example:</strong></span>
<pre class="programlisting"><span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">&gt;</span> <span class="keyword">void</span> <span class="identifier">foo</span> <span class="special">(</span> <span class="identifier">optional</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">opt</span> <span class="special">)</span> <span class="special">;</span>

<span class="identifier">foo</span> <span class="special">(</span> <span class="identifier">make_optional</span><span class="special">(</span><span class="number">1</span><span class="special">+</span><span class="number">1</span><span class="special">)</span> <span class="special">)</span> <span class="special">;</span> <span class="comment">// Creates an optional&lt;int&gt;</span>
</pre>
            </li>
</ul></div>
<p>
          <span class="inlinemediaobject"><img src="../../../images/space.png" alt="space"></span>
        </p>
<a name="reference_make_optional_bool_value"></a><div class="blockquote"><blockquote class="blockquote"><p>
            <code class="computeroutput"><span class="identifier">optional</span><span class="special">&lt;</span><span class="identifier">T</span></code> <span class="emphasis"><em>(not a ref)</em></span><code class="computeroutput"><span class="special">&gt;</span> <span class="identifier">make_optional</span><span class="special">(</span> <span class="keyword">bool</span> <span class="identifier">condition</span><span class="special">,</span>
            <span class="identifier">T</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">v</span> <span class="special">)</span></code>
          </p></blockquote></div>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
              <span class="bold"><strong>Returns: </strong></span> <code class="computeroutput"><span class="identifier">optional</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;(</span><span class="identifier">condition</span><span class="special">,</span><span class="identifier">v</span><span class="special">)</span></code> for the <span class="emphasis"><em>deduced</em></span>
              type <code class="computeroutput"><span class="identifier">T</span></code> of <code class="computeroutput"><span class="identifier">v</span></code>.
            </li>
<li class="listitem">
              <span class="bold"><strong>Example:</strong></span>
<pre class="programlisting"><span class="identifier">optional</span><span class="special">&lt;</span><span class="keyword">double</span><span class="special">&gt;</span> <span class="identifier">calculate_foo</span><span class="special">()</span>
<span class="special">{</span>
  <span class="keyword">double</span> <span class="identifier">val</span> <span class="special">=</span> <span class="identifier">compute_foo</span><span class="special">();</span>
  <span class="keyword">return</span> <span class="identifier">make_optional</span><span class="special">(</span><span class="identifier">is_not_nan_and_finite</span><span class="special">(</span><span class="identifier">val</span><span class="special">),</span><span class="identifier">val</span><span class="special">);</span>
<span class="special">}</span>

<span class="identifier">optional</span><span class="special">&lt;</span><span class="keyword">double</span><span class="special">&gt;</span> <span class="identifier">v</span> <span class="special">=</span> <span class="identifier">calculate_foo</span><span class="special">();</span>
<span class="keyword">if</span> <span class="special">(</span> <span class="special">!</span><span class="identifier">v</span> <span class="special">)</span>
  <span class="identifier">error</span><span class="special">(</span><span class="string">"foo wasn't computed"</span><span class="special">);</span>
</pre>
            </li>
</ul></div>
<p>
          <span class="inlinemediaobject"><img src="../../../images/space.png" alt="space"></span>
        </p>
<a name="reference_operator_compare_equal_optional_optional"></a><div class="blockquote"><blockquote class="blockquote"><p>
            <code class="computeroutput"><span class="keyword">bool</span> <span class="keyword">operator</span>
            <span class="special">==</span> <span class="special">(</span>
            <span class="identifier">optional</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">x</span><span class="special">,</span> <span class="identifier">optional</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">y</span> <span class="special">);</span></code>
          </p></blockquote></div>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
              <span class="bold"><strong>Requires:</strong></span> <code class="computeroutput"><span class="identifier">T</span></code>
              shall meet requirements of <a href="http://www.sgi.com/tech/stl/EqualityComparable.html" target="_top"><code class="computeroutput"><span class="identifier">EqualityComparable</span></code></a>.
            </li>
<li class="listitem">
              <span class="bold"><strong>Returns:</strong></span> If both <code class="computeroutput"><span class="identifier">x</span></code>
              and <code class="computeroutput"><span class="identifier">y</span></code> are initialized,
              <code class="computeroutput"><span class="special">(*</span><span class="identifier">x</span>
              <span class="special">==</span> <span class="special">*</span><span class="identifier">y</span><span class="special">)</span></code>.
              If only <code class="computeroutput"><span class="identifier">x</span></code> or <code class="computeroutput"><span class="identifier">y</span></code> is initialized, <code class="computeroutput"><span class="keyword">false</span></code>.
              If both are uninitialized, <code class="computeroutput"><span class="keyword">true</span></code>.
            </li>
<li class="listitem">
              <span class="bold"><strong>Notes:</strong></span> This definition guarantees
              that <code class="computeroutput"><span class="identifier">optional</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;</span></code>
              not containing a value is compared unequal to any <code class="computeroutput"><span class="identifier">optional</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;</span></code> containing any value, and equal
              to any other <code class="computeroutput"><span class="identifier">optional</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;</span></code> not containing a value. Pointers
              have shallow relational operators while <code class="computeroutput"><span class="identifier">optional</span></code>
              has deep relational operators. Do not use <code class="computeroutput"><span class="keyword">operator</span><span class="special">==</span></code> directly in generic code which expect
              to be given either an <code class="computeroutput"><span class="identifier">optional</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;</span></code> or a pointer; use <a href="../../../../../../utility/OptionalPointee.html#equal" target="_top"><code class="computeroutput"><span class="identifier">equal_pointees</span><span class="special">()</span></code></a>
              instead
            </li>
<li class="listitem">
              <span class="bold"><strong>Example:</strong></span>
<pre class="programlisting"><span class="identifier">optional</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;</span> <span class="identifier">oN</span><span class="special">,</span> <span class="identifier">oN_</span><span class="special">;</span>
<span class="identifier">optional</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;</span> <span class="identifier">o1</span><span class="special">(</span><span class="identifier">T</span><span class="special">(</span><span class="number">1</span><span class="special">)),</span> <span class="identifier">o1_</span><span class="special">(</span><span class="identifier">T</span><span class="special">(</span><span class="number">1</span><span class="special">));</span>
<span class="identifier">optional</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;</span> <span class="identifier">o2</span><span class="special">(</span><span class="identifier">T</span><span class="special">(</span><span class="number">2</span><span class="special">));</span>

<span class="identifier">assert</span> <span class="special">(</span> <span class="identifier">oN</span> <span class="special">==</span> <span class="identifier">oN</span> <span class="special">);</span>  <span class="comment">// Identity implies equality</span>
<span class="identifier">assert</span> <span class="special">(</span> <span class="identifier">o1</span> <span class="special">==</span> <span class="identifier">o1</span> <span class="special">);</span>  <span class="comment">//</span>

<span class="identifier">assert</span> <span class="special">(</span> <span class="identifier">oN</span> <span class="special">==</span> <span class="identifier">oN_</span> <span class="special">);</span> <span class="comment">// Both uninitialized compare equal</span>

<span class="identifier">assert</span> <span class="special">(</span> <span class="identifier">oN</span> <span class="special">!=</span> <span class="identifier">o1</span> <span class="special">);</span>  <span class="comment">// Initialized unequal to initialized.</span>

<span class="identifier">assert</span> <span class="special">(</span> <span class="identifier">o1</span> <span class="special">==</span> <span class="identifier">o1_</span> <span class="special">);</span> <span class="comment">// Both initialized compare as (*lhs == *rhs)</span>
<span class="identifier">assert</span> <span class="special">(</span> <span class="identifier">o1</span> <span class="special">!=</span> <span class="identifier">o2</span> <span class="special">);</span>  <span class="comment">//</span>
</pre>
            </li>
</ul></div>
<p>
          <span class="inlinemediaobject"><img src="../../../images/space.png" alt="space"></span>
        </p>
<a name="reference_operator_compare_less_optional_optional"></a><div class="blockquote"><blockquote class="blockquote"><p>
            <code class="computeroutput"><span class="keyword">bool</span> <span class="keyword">operator</span>
            <span class="special">&lt;</span> <span class="special">(</span>
            <span class="identifier">optional</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">x</span><span class="special">,</span> <span class="identifier">optional</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">y</span> <span class="special">);</span></code>
          </p></blockquote></div>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
              <span class="bold"><strong>Requires:</strong></span> Expression <code class="computeroutput"><span class="special">*</span><span class="identifier">x</span> <span class="special">&lt;</span> <span class="special">*</span><span class="identifier">y</span></code> shall be well-formed and its result
              shall be convertible to <code class="computeroutput"><span class="keyword">bool</span></code>.
            </li>
<li class="listitem">
              <span class="bold"><strong>Returns:</strong></span> <code class="computeroutput"><span class="special">(!</span><span class="identifier">y</span><span class="special">)</span> <span class="special">?</span> <span class="keyword">false</span> <span class="special">:</span> <span class="special">(!</span><span class="identifier">x</span><span class="special">)</span> <span class="special">?</span> <span class="keyword">true</span> <span class="special">:</span> <span class="special">*</span><span class="identifier">x</span> <span class="special">&lt;</span>
              <span class="special">*</span><span class="identifier">y</span></code>.
            </li>
<li class="listitem">
              <span class="bold"><strong>Notes:</strong></span> This definition guarantees
              that <code class="computeroutput"><span class="identifier">optional</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;</span></code>
              not containing a value is ordered as less than any <code class="computeroutput"><span class="identifier">optional</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;</span></code> containing any value, and equivalent
              to any other <code class="computeroutput"><span class="identifier">optional</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;</span></code> not containing a value. Pointers
              have shallow relational operators while <code class="computeroutput"><span class="identifier">optional</span></code>
              has deep relational operators. Do not use <code class="computeroutput"><span class="keyword">operator</span><span class="special">&lt;</span></code> directly in generic code which
              expect to be given either an <code class="computeroutput"><span class="identifier">optional</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;</span></code> or a pointer; use <a href="../../../../../../utility/OptionalPointee.html#less" target="_top"><code class="computeroutput"><span class="identifier">less_pointees</span><span class="special">()</span></code></a>
              instead. <code class="computeroutput"><span class="identifier">T</span></code> need not
              be <a href="http://www.sgi.com/tech/stl/LessThanComparable.html" target="_top"><code class="computeroutput"><span class="identifier">LessThanComparable</span></code></a>. Only
              single <code class="computeroutput"><span class="keyword">operator</span><span class="special">&lt;</span></code>
              is required. Other relational operations are defined in terms of this
              one. If <code class="computeroutput"><span class="identifier">T</span></code>'s <code class="computeroutput"><span class="keyword">operator</span><span class="special">&lt;</span></code>
              satisfies the axioms of <a href="http://www.sgi.com/tech/stl/LessThanComparable.html" target="_top"><code class="computeroutput"><span class="identifier">LessThanComparable</span></code></a> (transitivity,
              antisymmetry and irreflexivity), <code class="computeroutput"><span class="identifier">optional</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;</span></code> is <a href="http://www.sgi.com/tech/stl/LessThanComparable.html" target="_top"><code class="computeroutput"><span class="identifier">LessThanComparable</span></code></a>.
            </li>
<li class="listitem">
              <span class="bold"><strong>Example:</strong></span>
<pre class="programlisting"><span class="identifier">optional</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;</span> <span class="identifier">oN</span><span class="special">,</span> <span class="identifier">oN_</span><span class="special">;</span>
<span class="identifier">optional</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;</span> <span class="identifier">o0</span><span class="special">(</span><span class="identifier">T</span><span class="special">(</span><span class="number">0</span><span class="special">));</span>
<span class="identifier">optional</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;</span> <span class="identifier">o1</span><span class="special">(</span><span class="identifier">T</span><span class="special">(</span><span class="number">1</span><span class="special">));</span>

<span class="identifier">assert</span> <span class="special">(</span> <span class="special">!(</span><span class="identifier">oN</span> <span class="special">&lt;</span> <span class="identifier">oN</span><span class="special">)</span> <span class="special">);</span>  <span class="comment">// Identity implies equivalence</span>
<span class="identifier">assert</span> <span class="special">(</span> <span class="special">!(</span><span class="identifier">o1</span> <span class="special">&lt;</span> <span class="identifier">o1</span><span class="special">)</span> <span class="special">);</span>

<span class="identifier">assert</span> <span class="special">(</span> <span class="special">!(</span><span class="identifier">oN</span> <span class="special">&lt;</span> <span class="identifier">oN_</span><span class="special">)</span> <span class="special">);</span> <span class="comment">// Two uninitialized are equivalent</span>
<span class="identifier">assert</span> <span class="special">(</span> <span class="special">!(</span><span class="identifier">oN_</span> <span class="special">&lt;</span> <span class="identifier">oN</span><span class="special">)</span> <span class="special">);</span>

<span class="identifier">assert</span> <span class="special">(</span> <span class="identifier">oN</span> <span class="special">&lt;</span> <span class="identifier">o0</span> <span class="special">);</span>     <span class="comment">// Uninitialized is less than initialized</span>
<span class="identifier">assert</span> <span class="special">(</span> <span class="special">!(</span><span class="identifier">o0</span> <span class="special">&lt;</span> <span class="identifier">oN</span><span class="special">)</span> <span class="special">);</span>

<span class="identifier">assert</span> <span class="special">(</span> <span class="identifier">o1</span> <span class="special">&lt;</span> <span class="identifier">o2</span> <span class="special">)</span> <span class="special">;</span>    <span class="comment">// Two initialized compare as (*lhs &lt; *rhs)</span>
<span class="identifier">assert</span> <span class="special">(</span> <span class="special">!(</span><span class="identifier">o2</span> <span class="special">&lt;</span> <span class="identifier">o1</span><span class="special">)</span> <span class="special">)</span> <span class="special">;</span>
<span class="identifier">assert</span> <span class="special">(</span> <span class="special">!(</span><span class="identifier">o2</span> <span class="special">&lt;</span> <span class="identifier">o2</span><span class="special">)</span> <span class="special">)</span> <span class="special">;</span>
</pre>
            </li>
</ul></div>
<p>
          <span class="inlinemediaobject"><img src="../../../images/space.png" alt="space"></span>
        </p>
<a name="reference_operator_compare_not_equal_optional_optional"></a><div class="blockquote"><blockquote class="blockquote"><p>
            <code class="computeroutput"><span class="keyword">bool</span> <span class="keyword">operator</span>
            <span class="special">!=</span> <span class="special">(</span>
            <span class="identifier">optional</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">x</span><span class="special">,</span> <span class="identifier">optional</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">y</span> <span class="special">);</span></code>
          </p></blockquote></div>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
              <span class="bold"><strong>Returns: </strong></span> <code class="computeroutput"><span class="special">!(</span>
              <span class="identifier">x</span> <span class="special">==</span>
              <span class="identifier">y</span> <span class="special">);</span></code>
            </li></ul></div>
<p>
          <span class="inlinemediaobject"><img src="../../../images/space.png" alt="space"></span>
        </p>
<a name="reference_operator_compare_greater_optional_optional"></a><div class="blockquote"><blockquote class="blockquote"><p>
            <code class="computeroutput"><span class="keyword">bool</span> <span class="keyword">operator</span>
            <span class="special">&gt;</span> <span class="special">(</span>
            <span class="identifier">optional</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">x</span><span class="special">,</span> <span class="identifier">optional</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">y</span> <span class="special">);</span></code>
          </p></blockquote></div>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
              <span class="bold"><strong>Returns: </strong></span> <code class="computeroutput"><span class="special">(</span>
              <span class="identifier">y</span> <span class="special">&lt;</span>
              <span class="identifier">x</span> <span class="special">);</span></code>
            </li></ul></div>
<p>
          <span class="inlinemediaobject"><img src="../../../images/space.png" alt="space"></span>
        </p>
<a name="reference_operator_compare_less_or_equal_optional_optional"></a><div class="blockquote"><blockquote class="blockquote"><p>
            <code class="computeroutput"><span class="keyword">bool</span> <span class="keyword">operator</span>
            <span class="special">&lt;=</span> <span class="special">(</span>
            <span class="identifier">optional</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">x</span><span class="special">,</span> <span class="identifier">optional</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">y</span> <span class="special">);</span></code>
          </p></blockquote></div>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
              <span class="bold"><strong>Returns: </strong></span> <code class="computeroutput"><span class="special">!(</span>
              <span class="identifier">y</span> <span class="special">&lt;</span>
              <span class="identifier">x</span> <span class="special">);</span></code>
            </li></ul></div>
<p>
          <span class="inlinemediaobject"><img src="../../../images/space.png" alt="space"></span>
        </p>
<a name="reference_operator_compare_greater_or_equal_optional_optional"></a><div class="blockquote"><blockquote class="blockquote"><p>
            <code class="computeroutput"><span class="keyword">bool</span> <span class="keyword">operator</span>
            <span class="special">&gt;=</span> <span class="special">(</span>
            <span class="identifier">optional</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">x</span><span class="special">,</span> <span class="identifier">optional</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">y</span> <span class="special">);</span></code>
          </p></blockquote></div>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
              <span class="bold"><strong>Returns: </strong></span> <code class="computeroutput"><span class="special">!(</span>
              <span class="identifier">x</span> <span class="special">&lt;</span>
              <span class="identifier">y</span> <span class="special">);</span></code>
            </li></ul></div>
<p>
          <span class="inlinemediaobject"><img src="../../../images/space.png" alt="space"></span>
        </p>
<a name="reference_operator_compare_equal_optional_none"></a><div class="blockquote"><blockquote class="blockquote"><p>
            <code class="computeroutput"><span class="keyword">bool</span> <span class="keyword">operator</span>
            <span class="special">==</span> <span class="special">(</span>
            <span class="identifier">optional</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">x</span><span class="special">,</span> <span class="identifier">none_t</span> <span class="special">)</span>
            <span class="keyword">noexcept</span><span class="special">;</span></code>
          </p></blockquote></div>
<div class="blockquote"><blockquote class="blockquote"><p>
            <code class="computeroutput"><span class="keyword">bool</span> <span class="keyword">operator</span>
            <span class="special">==</span> <span class="special">(</span>
            <span class="identifier">none_t</span><span class="special">,</span>
            <span class="identifier">optional</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">x</span> <span class="special">)</span> <span class="keyword">noexcept</span><span class="special">;</span></code>
          </p></blockquote></div>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
              <span class="bold"><strong>Returns:</strong></span> <code class="computeroutput"><span class="special">!</span><span class="identifier">x</span></code>.
            </li>
<li class="listitem">
              <span class="bold"><strong>Notes:</strong></span> <code class="computeroutput"><span class="identifier">T</span></code>
              need not meet requirements of <a href="http://www.sgi.com/tech/stl/EqualityComparable.html" target="_top"><code class="computeroutput"><span class="identifier">EqualityComparable</span></code></a>.
            </li>
</ul></div>
<p>
          <span class="inlinemediaobject"><img src="../../../images/space.png" alt="space"></span>
        </p>
<a name="reference_operator_compare_not_equal_optional_none"></a><div class="blockquote"><blockquote class="blockquote"><p>
            <code class="computeroutput"><span class="keyword">bool</span> <span class="keyword">operator</span>
            <span class="special">!=</span> <span class="special">(</span>
            <span class="identifier">optional</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">x</span><span class="special">,</span> <span class="identifier">none_t</span> <span class="special">)</span>
            <span class="keyword">noexcept</span><span class="special">;</span></code>
          </p></blockquote></div>
<div class="blockquote"><blockquote class="blockquote"><p>
            <code class="computeroutput"><span class="keyword">bool</span> <span class="keyword">operator</span>
            <span class="special">!=</span> <span class="special">(</span>
            <span class="identifier">none_t</span><span class="special">,</span>
            <span class="identifier">optional</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">x</span> <span class="special">)</span> <span class="keyword">noexcept</span><span class="special">;</span></code>
          </p></blockquote></div>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
              <span class="bold"><strong>Returns: </strong></span> <code class="computeroutput"><span class="special">!(</span>
              <span class="identifier">x</span> <span class="special">==</span>
              <span class="identifier">y</span> <span class="special">);</span></code>
            </li></ul></div>
<p>
          <span class="inlinemediaobject"><img src="../../../images/space.png" alt="space"></span>
        </p>
<a name="reference_swap_optional_optional"></a><div class="blockquote"><blockquote class="blockquote"><p>
            <code class="computeroutput"><span class="keyword">void</span> <span class="identifier">swap</span>
            <span class="special">(</span> <span class="identifier">optional</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;&amp;</span> <span class="identifier">x</span><span class="special">,</span> <span class="identifier">optional</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;&amp;</span> <span class="identifier">y</span>
            <span class="special">)</span> <span class="special">;</span></code>
          </p></blockquote></div>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
              <span class="bold"><strong>Requires:</strong></span> Lvalues of type <code class="computeroutput"><span class="identifier">T</span></code> shall be swappable and <code class="computeroutput"><span class="identifier">T</span></code> shall be <code class="computeroutput"><span class="identifier">MoveConstructible</span></code>.
            </li>
<li class="listitem">
<p class="simpara">
              <span class="bold"><strong>Effects:</strong></span>
            </p>
<div class="informaltable"><table class="table">
<colgroup>
<col>
<col>
<col>
</colgroup>
<thead><tr></tr></thead>
<tbody>
<tr>
<td>
                    </td>
<td>
                      <p>
                        <span class="bold"><strong><code class="computeroutput"><span class="special">*</span><span class="keyword">this</span></code> contains a value</strong></span>
                      </p>
                    </td>
<td>
                      <p>
                        <span class="bold"><strong><code class="computeroutput"><span class="special">*</span><span class="keyword">this</span></code> does not contain a value</strong></span>
                      </p>
                    </td>
</tr>
<tr>
<td>
                      <p>
                        <span class="bold"><strong><code class="computeroutput"><span class="identifier">rhs</span></code>
                        contains a value</strong></span>
                      </p>
                    </td>
<td>
                      <p>
                        calls <code class="computeroutput"><span class="identifier">swap</span><span class="special">(*(*</span><span class="keyword">this</span><span class="special">),</span> <span class="special">*</span><span class="identifier">rhs</span><span class="special">)</span></code>
                      </p>
                    </td>
<td>
                      <p>
                        initializes the contained value of <code class="computeroutput"><span class="special">*</span><span class="keyword">this</span></code> as if direct-initializing
                        an object of type <code class="computeroutput"><span class="identifier">T</span></code>
                        with the expression <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">move</span><span class="special">(*</span><span class="identifier">rhs</span><span class="special">)</span></code>, followed by <code class="computeroutput"><span class="identifier">rhs</span><span class="special">.</span><span class="identifier">val</span><span class="special">-&gt;</span><span class="identifier">T</span><span class="special">::~</span><span class="identifier">T</span><span class="special">()</span></code>,
                        <code class="computeroutput"><span class="special">*</span><span class="keyword">this</span></code>
                        contains a value and <code class="computeroutput"><span class="identifier">rhs</span></code>
                        does not contain a value
                      </p>
                    </td>
</tr>
<tr>
<td>
                      <p>
                        <span class="bold"><strong><code class="computeroutput"><span class="identifier">rhs</span></code>
                        does not contain a value</strong></span>
                      </p>
                    </td>
<td>
                      <p>
                        initializes the contained value of <code class="computeroutput"><span class="identifier">rhs</span></code>
                        as if direct-initializing an object of type <code class="computeroutput"><span class="identifier">T</span></code> with the expression
                        <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">move</span><span class="special">(*(*</span><span class="keyword">this</span><span class="special">))</span></code>,
                        followed by <code class="computeroutput"><span class="identifier">val</span><span class="special">-&gt;</span><span class="identifier">T</span><span class="special">::~</span><span class="identifier">T</span><span class="special">()</span></code>, <code class="computeroutput"><span class="special">*</span><span class="keyword">this</span></code> does not contain a value
                        and <code class="computeroutput"><span class="identifier">rhs</span></code> contains
                        a value
                      </p>
                    </td>
<td>
                      <p>
                        no effect
                      </p>
                    </td>
</tr>
</tbody>
</table></div>
</li>
<li class="listitem">
              <span class="bold"><strong>Postconditions:</strong></span> The states of <code class="computeroutput"><span class="identifier">x</span></code> and <code class="computeroutput"><span class="identifier">y</span></code>
              interchanged.
            </li>
<li class="listitem">
              <span class="bold"><strong>Throws:</strong></span> If both are initialized, whatever
              <code class="computeroutput"><span class="identifier">swap</span><span class="special">(</span><span class="identifier">T</span><span class="special">&amp;,</span><span class="identifier">T</span><span class="special">&amp;)</span></code>
              throws. If only one is initialized, whatever <code class="computeroutput"><span class="identifier">T</span><span class="special">::</span><span class="identifier">T</span> <span class="special">(</span> <span class="identifier">T</span><span class="special">&amp;&amp;</span> <span class="special">)</span></code>
              throws.
            </li>
<li class="listitem">
              <span class="bold"><strong>Example:</strong></span>
<pre class="programlisting"><span class="identifier">T</span> <span class="identifier">x</span><span class="special">(</span><span class="number">12</span><span class="special">);</span>
<span class="identifier">T</span> <span class="identifier">y</span><span class="special">(</span><span class="number">21</span><span class="special">);</span>
<span class="identifier">optional</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;</span> <span class="identifier">def0</span> <span class="special">;</span>
<span class="identifier">optional</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;</span> <span class="identifier">def1</span> <span class="special">;</span>
<span class="identifier">optional</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;</span> <span class="identifier">optX</span><span class="special">(</span><span class="identifier">x</span><span class="special">);</span>
<span class="identifier">optional</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;</span> <span class="identifier">optY</span><span class="special">(</span><span class="identifier">y</span><span class="special">);</span>

<span class="identifier">boost</span><span class="special">::</span><span class="identifier">swap</span><span class="special">(</span><span class="identifier">def0</span><span class="special">,</span><span class="identifier">def1</span><span class="special">);</span> <span class="comment">// no-op</span>

<span class="identifier">boost</span><span class="special">::</span><span class="identifier">swap</span><span class="special">(</span><span class="identifier">def0</span><span class="special">,</span><span class="identifier">optX</span><span class="special">);</span>
<span class="identifier">assert</span> <span class="special">(</span> <span class="special">*</span><span class="identifier">def0</span> <span class="special">==</span> <span class="identifier">x</span> <span class="special">);</span>
<span class="identifier">assert</span> <span class="special">(</span> <span class="special">!</span><span class="identifier">optX</span> <span class="special">);</span>

<span class="identifier">boost</span><span class="special">::</span><span class="identifier">swap</span><span class="special">(</span><span class="identifier">def0</span><span class="special">,</span><span class="identifier">optX</span><span class="special">);</span> <span class="comment">// Get back to original values</span>

<span class="identifier">boost</span><span class="special">::</span><span class="identifier">swap</span><span class="special">(</span><span class="identifier">optX</span><span class="special">,</span><span class="identifier">optY</span><span class="special">);</span>
<span class="identifier">assert</span> <span class="special">(</span> <span class="special">*</span><span class="identifier">optX</span> <span class="special">==</span> <span class="identifier">y</span> <span class="special">);</span>
<span class="identifier">assert</span> <span class="special">(</span> <span class="special">*</span><span class="identifier">optY</span> <span class="special">==</span> <span class="identifier">x</span> <span class="special">);</span>
</pre>
            </li>
</ul></div>
<p>
          <span class="inlinemediaobject"><img src="../../../images/space.png" alt="space"></span>
        </p>
<a name="reference_swap_optional_reference"></a><div class="blockquote"><blockquote class="blockquote"><p>
            <code class="computeroutput"><span class="keyword">void</span> <span class="identifier">swap</span>
            <span class="special">(</span> <span class="identifier">optional</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&amp;&gt;&amp;</span> <span class="identifier">x</span><span class="special">,</span> <span class="identifier">optional</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&amp;&gt;&amp;</span> <span class="identifier">y</span>
            <span class="special">)</span> <span class="keyword">noexcept</span>
            <span class="special">;</span></code>
          </p></blockquote></div>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
              <span class="bold"><strong>Postconditions:</strong></span> <code class="computeroutput"><span class="identifier">x</span></code>
              refers to what <code class="computeroutput"><span class="identifier">y</span></code> referred
              to before the swap (if anything). <code class="computeroutput"><span class="identifier">y</span></code>
              refers to whatever <code class="computeroutput"><span class="identifier">x</span></code>
              referred to before the swap.
            </li>
<li class="listitem">
              <span class="bold"><strong>Example:</strong></span>
<pre class="programlisting"><span class="identifier">T</span> <span class="identifier">x</span><span class="special">(</span><span class="number">12</span><span class="special">);</span>
<span class="identifier">T</span> <span class="identifier">y</span><span class="special">(</span><span class="number">21</span><span class="special">);</span>

<span class="identifier">optional</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&amp;&gt;</span> <span class="identifier">opt0</span><span class="special">;</span>
<span class="identifier">optional</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&amp;&gt;</span> <span class="identifier">optX</span> <span class="special">(</span><span class="identifier">x</span><span class="special">);</span>
<span class="identifier">optional</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&amp;&gt;</span> <span class="identifier">optY</span> <span class="special">(</span><span class="identifier">y</span><span class="special">);</span>

<span class="identifier">boost</span><span class="special">::</span><span class="identifier">swap</span><span class="special">(</span><span class="identifier">optX</span><span class="special">,</span> <span class="identifier">optY</span><span class="special">);</span>
<span class="identifier">assert</span> <span class="special">(</span><span class="identifier">addressof</span><span class="special">(*</span><span class="identifier">optX</span><span class="special">)</span> <span class="special">==</span> <span class="identifier">addressof</span><span class="special">(</span><span class="identifier">y</span><span class="special">));</span>
<span class="identifier">assert</span> <span class="special">(</span><span class="identifier">addressof</span><span class="special">(*</span><span class="identifier">optY</span><span class="special">)</span> <span class="special">==</span> <span class="identifier">addressof</span><span class="special">(</span><span class="identifier">x</span><span class="special">));</span>

<span class="identifier">boost</span><span class="special">::</span><span class="identifier">swap</span><span class="special">(</span><span class="identifier">opt0</span><span class="special">,</span> <span class="identifier">optX</span><span class="special">);</span>
<span class="identifier">assert</span> <span class="special">(</span> <span class="identifier">opt0</span> <span class="special">);</span>
<span class="identifier">assert</span> <span class="special">(</span> <span class="special">!</span><span class="identifier">optX</span> <span class="special">);</span>
<span class="identifier">assert</span> <span class="special">(</span><span class="identifier">addressof</span><span class="special">(*</span><span class="identifier">opt0</span><span class="special">)</span> <span class="special">==</span> <span class="identifier">addressof</span><span class="special">(</span><span class="identifier">y</span><span class="special">));</span>
</pre>
              [endsect]
            </li>
</ul></div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright &#169; 2003-2007 Fernando Luis Cacciola Carballal<br>Copyright &#169; 2014-2016 Andrzej Krzemie&#324;ski<p>
        Distributed under the Boost Software License, Version 1.0. (See accompanying
        file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
      </p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="detailed_semantics____optional_references.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../../../optional/reference/header__boost_optional_optional_hpp_.html"><img src="../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="header__boost_optional_hpp_.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>
